package com.kawins.mina.util;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

/**
 * Created by think on 2016/1/6.
 */
public class ReturnData {

	/** invalid argument **/
	public static final int CODE_INVALID_ARGUMENT = 300;

	/** request successful **/
	public static final int CODE_OK = 200;

	public static final int CODE_ERROR = 500;

	private final String KEY_CODE = "code";
	private final String KEY_MESSAGE = "message";

	private Map<String, Object> data;

	public ReturnData() {
	}

	public ReturnData(int code) {
		data = new HashMap<>();
		data.put(KEY_CODE, code);
		data.put(KEY_MESSAGE, "");
	}

	public ReturnData(int code, String message) {
		data = new HashMap<>();
		data.put(KEY_CODE, code);
		data.put(KEY_MESSAGE, message == null ? "" : message);
	}

	public ReturnData putData(String key, Object object) {
		data.put(key, object);
		return this;
	}

	@Override
	public String toString() {
		return JSONObject.fromObject(data).toString();
	}
}
